package com.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2018/5/15.
 */

public class dealActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText number1;
    private EditText number2;
    private EditText deal;
    private TextView result;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.deal);
        findViewById(R.id.bt_butt).setOnClickListener(this);
        number1=findViewById(R.id.num1);
        number2=findViewById(R.id.num2);
        deal=findViewById(R.id.et_fuhao);
        result=findViewById(R.id.result);
    }
    @Override
    public void onClick(View view) {
        float num1 = Float.parseFloat(number1.getText().toString());
        float num2 = Float.parseFloat(number2.getText().toString());
        String del =deal.getText().toString();
        float total;
        switch (del){
            case "*":
                total=num1*num2;
                result.setText(total+"");
                break;
            case "/":
                total=num1/num2;
                result.setText(total+"");
                break;
            case "+":
                total=num1+num2;
                result.setText(total+"");
                break;
            case "-":
                total=num1-num2;
                result.setText(total+"");
                break;
            default:
                Toast.makeText(this,"运算符输入错误请重新输入",Toast.LENGTH_SHORT).show();
        }
    }
}
